package pl.koziolekweb.szkola.KFWebPageReader;

// KF-WebPageReader/WebPageReader.java
 
import java.net.*;
import java.io.*;

/**
 *   Uzycie:
 *              java WebPageReader <url>
 *          lub
 *              java WebPageReader
 */
public class WebPageReader {

    public static void main(String[] args) {

        String urlString = args.length == 0 ?
                "http://www.google.com" : args[0];
        URLConnection connection = null;

        try {
            URL url = new URL(urlString);
            connection = url.openConnection();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

        BufferedReader in = null;
        try {
            in = new BufferedReader(
                     new InputStreamReader(
                         connection.getInputStream()));
            String line;
            while ( (line = in.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try { in.close(); }
            catch (Exception ignored) { }
        }
    }
}
